package com.ruoyi.jjyh.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.jjyh.domain.JjyhMassage;
import com.ruoyi.jjyh.service.IJjyhMassageService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 消息Controller
 * 
 * @author ruoyi
 * @date 2020-11-24
 */
@Controller
@RequestMapping("/jjyh/massage")
public class JjyhMassageController extends BaseController
{
    private String prefix = "jjyh/massage";

    @Autowired
    private IJjyhMassageService jjyhMassageService;

    @RequiresPermissions("jjyh:massage:view")
    @GetMapping()
    public String massage()
    {
        return prefix + "/massage";
    }

    /**
     * 查询消息列表
     */
    @RequiresPermissions("jjyh:massage:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JjyhMassage jjyhMassage)
    {
        startPage();
        List<JjyhMassage> list = jjyhMassageService.selectJjyhMassageList(jjyhMassage);
        return getDataTable(list);
    }

    /**
     * 导出消息列表
     */
    @RequiresPermissions("jjyh:massage:export")
    @Log(title = "消息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JjyhMassage jjyhMassage)
    {
        List<JjyhMassage> list = jjyhMassageService.selectJjyhMassageList(jjyhMassage);
        ExcelUtil<JjyhMassage> util = new ExcelUtil<JjyhMassage>(JjyhMassage.class);
        return util.exportExcel(list, "massage");
    }

    /**
     * 新增消息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存消息
     */
    @RequiresPermissions("jjyh:massage:add")
    @Log(title = "消息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JjyhMassage jjyhMassage)
    {
        //PC端新增系统消息
        jjyhMassage.setType("1");
        return toAjax(jjyhMassageService.insertJjyhMassage(jjyhMassage));
    }

    /**
     * 修改消息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        JjyhMassage jjyhMassage = jjyhMassageService.selectJjyhMassageById(id);
        mmap.put("jjyhMassage", jjyhMassage);
        return prefix + "/edit";
    }

    /**
     * 修改保存消息
     */
    @RequiresPermissions("jjyh:massage:edit")
    @Log(title = "消息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JjyhMassage jjyhMassage)
    {
        return toAjax(jjyhMassageService.updateJjyhMassage(jjyhMassage));
    }

    /**
     * 删除消息
     */
    @RequiresPermissions("jjyh:massage:remove")
    @Log(title = "消息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jjyhMassageService.deleteJjyhMassageByIds(ids));
    }
}
